package com.innovatio.validator.handlers;

import com.innovatio.validator.annotations.ValidateLength;
import com.innovatio.validator.exceptions.ValidatorException;
import com.innovatio.validator.Validable;
import com.innovatio.validator.ValidationErrors;
import com.innovatio.utils.validations.InputValidationUtils;


/**
 * This code is property of Innovatio Software Solutions, Inc.
 * Project PaySmart
 * User: Ramon
 * Refactored by: Edxe
 * Date: Mar 4, 2009
 * Time: 1:33:41 PM
 */
public class ValidateLengthHandler implements ValidationHandler<ValidateLength> {

    public ValidationErrors.Error validate(ValidateLength settings, Validable container,String fieldName,String  value) throws ValidatorException {
        String i = (value != null) ? value.trim() : "";

        if(!InputValidationUtils.isValidStringField(i,settings.min(),settings.max())){
            return new ValidationErrors.Error(fieldName,settings.i18nBundleKey());
        }
        return null;
    }

}
